var confirm_ok;
var confirm_no;
function file_mouseover(i)
{
document.getElementById("file"+i).style.backgroundColor="#DDDDDD";
document.getElementById("tfile"+i).style.backgroundColor="#DDDDDD";
}
function file_mouseout(i)
{
if(!document.getElementById("cfile"+i).checked){
document.getElementById("file"+i).style.backgroundColor="#F0F0F0";
document.getElementById("tfile"+i).style.backgroundColor="#F0F0F0";
}
}
function checkboxSelectedAll(i){

for(var j=0;j<i;j++){
  document.getElementById("cfile"+j).checked=document.getElementById("cAll").checked;
checkboxSelected(j);
}

}
function checkboxSelected(i)
{
    if(document.getElementById("cfile"+i).checked)
    {
        document.getElementById("file"+i).style.backgroundColor="#DDDDDD";
		 document.getElementById("tfile"+i).style.backgroundColor="#DDDDDD";
    }
    else{
      document.getElementById("file"+i).style.backgroundColor="#F0F0F0";
	  document.getElementById("tfile"+i).style.backgroundColor="#F0F0F0";
	  }
}
function fileClicked(i)
{

    if(document.getElementById("hfile"+i).value=="0"){
        document.getElementById("cfile"+i).checked=true;
        document.getElementById("hfile"+i).value="1";
        }
    else{
        document.getElementById("cfile"+i).checked=false;
         document.getElementById("hfile"+i).value="0";
        }
    checkboxSelected(i);
}
function confirmOK(){
$(".disable").hide();
$(".confirm").hide();
confirm_ok();
}
function confirmNO(){
$(".disable").hide();
$(".confirm").hide();
confirm_no();
}
function MYconfirm(title,msg,ok,no)
{
$(".disable").show();
$(".confirm").show();
   document.getElementById("confirm_t").innerHTML=title;
    document.getElementById("confirm_m").innerHTML=msg;
	confirm_ok=ok;
	confirm_no=no;
}
function fileDeleted(i,path)
{
 MYconfirm("Message","Do you want to delete the file?",function(){
 			ajaxLoader(path,"");
			document.getElementById("file"+i).style.display="none";
 },function(){
          document.getElementById("hfile"+i).value="0";
         fileClicked(i);
 });


}

function createFolder(){
document.getElementById("createFolder").value="NewFolder";
$("#newFolder").show();
}
function saveCreateFolder(){
		var value=document.getElementById("createFolder").value;
		if(value.length==0)
		;
		else{
		ajaxLoader('createFolder/'+value,'');
		refresh('refresh');
		}
}

function refresh(i){
	$(".disable").show();
	$("#loading").show();

	setTimeout("window.location.replace('"+i+"')",1000);
}


function changedPermission(e,i)
{

        document.getElementById("filePermission").style.left=e.clientX+"px";
         document.getElementById("filePermission").style.top=e.clientY+"px";
		  $(".disable").show();
          $("#filePermission").show();

}
function renameFile(i)
{
			document.getElementById("tfile"+i).style.border="1px solid #CCCCCC";
			document.getElementById("tfile"+i).readOnly =false;
		
}
function saveChange(i,path)
{
			document.getElementById("tfile"+i).style.border="0px solid #CCCCCC";
			document.getElementById("tfile"+i).readOnly =true;
			ajaxLoader(path,"name="+document.getElementById("tfile"+i).value);
			
}
function fileDownload(i){
		window.location.replace(i);
}
function folderBrowse(i){
		window.location.replace(i);
}
function backToUp(i){
		window.location.replace(i);
}
function ajaxLoader(path,pram)
{

var xmlhttp;
if (path.length==0)
  {
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
			//xmlhttp.responseText;
			;
    }
  }
xmlhttp.open("POST",path,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(pram);
}
function showUpload()
{
  $(".disable").show();
  $(".upload").show();	
}
function cancelUpload(){
	
	document.getElementById("files").value="";
  $(".disable").hide();
  $(".upload").hide();	
   $(".chooseFile").show();
   document.getElementById('list').innerHTML="";
   document.getElementById('step').style.width = 0 + '%';
   document.getElementById('step').innerHTML = 0 + '%';
   $(".progressBar").hide();
refresh('refresh');

}
var fileObject;
 function handleFileSelect(evt) {
    var files = evt.target.files;
	fileObject=files[0];
    var output = [];
    for (var i = 0, f; f = files[i]; i++) {
      output.push('<li>', escape(f.name),' - ',f.size, ' bytes,','</li>');
    }
    document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
}



function startUpload(){

 $(".chooseFile").hide();
$(".progressBar").show();
	var fileReader = new FileReader();
	fileReader.onprogress = updateProgress;
	fileReader.onload = function(e) {
			var xmlHttpRequest = new XMLHttpRequest();
  
			xmlHttpRequest.open("POST", 'upload', true);
			var dashes = '--';
			var boundary = 'aperturephotoupload';
			var crlf = "\r\n";
			xmlHttpRequest.onreadystatechange=function()
			{
				if (xmlHttpRequest.readyState==4 && xmlHttpRequest.status==200)
				{
						if(xmlHttpRequest.responseText=="OK"){
							document.getElementById('step').style.width = 100 + '%';
							document.getElementById('step').innerHTML = 100 + '%';
							setTimeout("cancelUpload()",1000);
						}
				}
			}

		if ( fileObject.type == '' ){
			filetype = 'application/octet-stream';
		} else {
			filetype = fileObject.type;
		}

		var data = dashes + boundary + crlf + "Content-Disposition: form-data;" + "name=\"file\";" + "filename=\"" + unescape(encodeURIComponent(fileObject.name)) + "\"" + crlf + "Content-Type: " + filetype + crlf + crlf + e.target.result + crlf + dashes + boundary + dashes;

		xmlHttpRequest.setRequestHeader("Content-Type", "multipart/form-data;boundary=" + boundary);
		xmlHttpRequest.send(data);

	}
	fileReader.readAsBinaryString(fileObject);
}
 function updateProgress(evt) {
    if (evt.lengthComputable) {
      var percentLoaded = Math.round((evt.loaded / evt.total) * 100);
      if (percentLoaded < 100) {
        document.getElementById('step').style.width = percentLoaded + '%';
        document.getElementById('step').innerHTML = percentLoaded + '%';
      }
    }
  }


